package com.zxd.encoding;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * ClassName:TestEncoding
 * Package:com.zxd.encoding
 *
 * @Date:2023/10/9 17:46
 * @Author:zxde
 */
public class TestEncoding {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String str = "a在n";

        //GBK编码中汉字占两个字节（开头为1），字母数字占一个字节（开头为0）； 0xxxxxxx 1xxxxxxx  xxxxxxxx 0xxxxxxxx (0开头为正数 1开头为负数)

        byte[] gbkEncoding = str.getBytes("GBK");

        //UTF-8中 汉字占3个字节，开头为1110xxxx 10xxxxxx 10xxxxxx,中间的？表示无法匹配 utf-8，也无法匹配ASCII
        String strUTF_8 = new String(gbkEncoding, StandardCharsets.UTF_8);

        String strGBK = new String(gbkEncoding, "GBK");


        System.out.println(Arrays.toString(gbkEncoding));
    }
}
